<template>
  <basic-container>
    <avue-crud
        ref="dynamicFormCrud"
        v-bind="bindVal"
        v-on="onEvent"
        @cell-dblclick="rowDblclick"
        :page.sync="page"
        v-model="startForm">
      <template slot-scope="{type,size,row}" slot="menuBtn">
        <el-dropdown-item divided icon="el-icon-edit" :size="size" @click.native="designForm(row)" :type="type">设计
        </el-dropdown-item>
        <el-dropdown-item divided icon="el-icon-search" :size="size" @click.native="viewData(row)" :type="type">查看数据
        </el-dropdown-item>
        <el-dropdown-item slot="reference" v-if="row.isSyncDataBase===0" @click.native="syncDataBaseFrom(row)"
                          icon="el-icon-refresh" :size="size"
                          :type="type">同步表单
        </el-dropdown-item>
        <el-dropdown-item v-if="row.isCreateMenu===0" divided icon="el-icon-circle-plus-outline" :size="size"
                          @click.native="createMenu(row)" :type="type">创建菜单
        </el-dropdown-item>
        <el-dropdown-item divided icon="el-icon-share" :size="size"
                          @click.native="shareForm(row)" :type="type">分享
        </el-dropdown-item>
      </template>
    </avue-crud>

    <create-menu ref="createMenu" @change="refreshChange"></create-menu>
    <create-share ref="createShare" @change="refreshChange"></create-share>
  </basic-container>
</template>

<script>
import createMenu from "@/views/start/formEngine/form/createMenu";
import createShare from "@/views/start/formEngine/form/createShare";

import {createStartMixin} from "@/mixins/start-crud.js"
import {synchronizationTable} from "@/api/start/formEngine/formApi";

export default {
  mixins: [createStartMixin({name: "start/formEngine/form"})],
  components: {createMenu, createShare},
  created() {

  },
  methods: {
    beforeOpenAddDialog(form, done) {
      let routerJump = this.$router.resolve({path: '/start/formEngine/design/create'})
      window.open(routerJump.href, '_blank');
      return true;
    },
    designForm(row) {
      let routerJump = this.$router.resolve({path: '/start/formEngine/design/' + row.id})
      window.open(routerJump.href, '_blank');
    },
    viewData(row) {
      let routerJump = this.$router.resolve({path: '/formDesign/data/previewTableData/' + row.id})
      window.open(routerJump.href, '_blank');
    },
    createMenu(row) {
      this.$refs.createMenu.show(row)

    },
    rowDblclick(row, column) {
      this.$refs.dynamicFormCrud.rowEdit(row, row.$index)
    },
    shareForm(row) {
      this.$refs.createShare.show(row);
    },
    syncDataBaseFrom(row) {
      this.$confirm(`此操作将可能导致【${row.name}】表单数据丢失！, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return synchronizationTable(row.id)
      }).then(res => {
        this.$message({
          showClose: true,
          message: '同步成功',
          type: 'success'
        });
        this.getList();
      })
    }
  }
}
</script>

<style scoped>

</style>
